package com.stylefeng.guns.modular.pay.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.pay.model.AccountHistory;
import com.stylefeng.guns.modular.pay.model.Trans;
import com.stylefeng.guns.modular.pay.service.IAccountHistoryService;

/**
 * 账户历史控制器
 *
 * @author fengshuonan
 * @Date 2018-08-24 15:19:07
 */
@Controller
@RequestMapping("/accountHistory")
public class AccountHistoryController extends BaseController {

    private String PREFIX = "/pay/accountHistory/";

    @Autowired
    private IAccountHistoryService accountHistoryService;

    /**
     * 跳转到账户历史首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "accountHistory.html";
    }

    /**
     * 跳转到添加账户历史
     */
    @RequestMapping("/accountHistory_add")
    public String accountHistoryAdd() {
        return PREFIX + "accountHistory_add.html";
    }

    /**
     * 跳转到修改账户历史
     */
    @RequestMapping("/accountHistory_update/{accountHistoryId}")
    public String accountHistoryUpdate(@PathVariable Integer accountHistoryId, Model model) {
        AccountHistory accountHistory = accountHistoryService.selectById(accountHistoryId);
        model.addAttribute("item",accountHistory);
        LogObjectHolder.me().set(accountHistory);
        return PREFIX + "accountHistory_edit.html";
    }

    /**
     * 获取账户历史列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(AccountHistory history) {
    	 Page<AccountHistory> page = new PageFactory<AccountHistory>().defaultPage();
    	//商户数据过滤
    	 if(ShiroKit.getUser().getRoleList().contains(6)){
    		 String account = ShiroKit.getUser().getAccount();
    		 history.setMchNo(account);
    	 }
         List<AccountHistory> result = accountHistoryService.list(page,history);
         page.setRecords(result);
         return super.packForBT(page);
       
    }

    /**
     * 新增账户历史
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(AccountHistory accountHistory) {
        accountHistoryService.insert(accountHistory);
        return SUCCESS_TIP;
    }

    /**
     * 删除账户历史
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer accountHistoryId) {
        accountHistoryService.deleteById(accountHistoryId);
        return SUCCESS_TIP;
    }

    /**
     * 修改账户历史
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(AccountHistory accountHistory) {
        accountHistoryService.updateById(accountHistory);
        return SUCCESS_TIP;
    }

    /**
     * 账户历史详情
     */
    @RequestMapping(value = "/detail/{accountHistoryId}")
    @ResponseBody
    public Object detail(@PathVariable("accountHistoryId") Integer accountHistoryId) {
        return accountHistoryService.selectById(accountHistoryId);
    }
}
